package com.hy.service.impl;

import java.util.Date;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.hy.base.DozerBase;
import com.hy.dao.AttrMapper;
import com.hy.form.input.AttrAddForm;
import com.hy.model.Attr;
import com.hy.service.IAttrService;

@Service
public class AttrServiceImpl extends DozerBase implements IAttrService {
	
	static final Logger logger = LoggerFactory.getLogger(AttrServiceImpl.class);
	
	private AttrMapper attrMapper;

	/*
	 * (non-Javadoc)
	 * @see com.hy.service.IAttrService#add(com.hy.form.input.AttrAddForm)
	 */
	@Override
	public void add(AttrAddForm attrAddForm) {
		Attr attr = this.getDozerMapper().map(attrAddForm, Attr.class);
		Date date = new Date();
		if(StringUtils.isEmpty(attr.getGuid())) { //新增
			attr.setGuid(UUID.randomUUID().toString());
			attr.setCreate_time(date);
			attr.setUpdate_time(date);
			attrMapper.insertSelective(attr);
		} else { //修改
			attr.setUpdate_time(date);
			attrMapper.updateByPrimaryKeySelective(attr);
		}
	}

	/*
	 * (non-Javadoc)
	 * @see com.hy.service.IAttrService#del(java.lang.String)
	 */
	@Override
	public void del(String guid) {
		//TODO:删除逻辑
		attrMapper.deleteByPrimaryKey(guid);
	}

}
